   /*
    * Created by JFormDesigner on Fri Nov 01 16:12:38 CST 2024
    */

   package com.hafu.view.GYS;

   import com.hafu.model.GysInfo;
   import com.hafu.service.GysInfoService;
   import com.hafu.util.StringUtil;

   import java.awt.*;
   import java.awt.event.*;
   import java.sql.SQLException;
   import javax.swing.*;
   import javax.swing.GroupLayout;

   /**
    * @author 25188
    */
   public class AddGYSFrm extends JFrame {
       private GysInfoService gysInfoService = new GysInfoService();
       public AddGYSFrm() {
           initComponents();
       }

       private void subGYSbtn(ActionEvent e) throws SQLException {
           // TODO add your code here 添加供应商信息事件
           String name = textField1.getText();
           String tel = textField2.getText();
           if(StringUtil.isEmpty(name) && StringUtil.isEmpty(tel)){
               JOptionPane.showMessageDialog(null, "供应商名称和电话不能为空");
               return;
           }
           if(StringUtil.isEmpty(name)){
               JOptionPane.showMessageDialog(null, "供应商名称不能为空");
               return;
           }if (StringUtil.isEmpty(tel)){
               JOptionPane.showMessageDialog(null, "供应商电话不能为空");
               return;
           }if (tel.length() != 11){
            JOptionPane.showMessageDialog(null, "供应商电话格式不正确");
            return;
            }
           GysInfo gysInfo = new GysInfo(name, tel);
           Boolean aBoolean = gysInfoService.addGysInfo(gysInfo);
           if (aBoolean){
               JOptionPane.showMessageDialog(null, "添加成功");
               this.dispose();
           }else {
               JOptionPane.showMessageDialog(null, "添加失败");
           }
       }

       private void initComponents() {
           // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
           label1 = new JLabel();
           textField1 = new JTextField();
           label2 = new JLabel();
           textField2 = new JTextField();
           subGYSbtn = new JButton();

           //======== this ========
           setTitle("添加供应商");

           Container contentPane = getContentPane();

           //---- label1 ----
           label1.setText("供应商名称");

           //---- label2 ----
           label2.setText("供应商电话");

           //---- subGYSbtn ----
           subGYSbtn.setText("添加");
           subGYSbtn.addActionListener(e -> {try {
subGYSbtn(e);} catch (SQLException ex) {
    throw new RuntimeException(ex);
}});

           GroupLayout contentPaneLayout = new GroupLayout(contentPane);
           contentPane.setLayout(contentPaneLayout);
           contentPaneLayout.setHorizontalGroup(
                   contentPaneLayout.createParallelGroup()
                           .addGroup(contentPaneLayout.createSequentialGroup()
                                   .addGap(108, 108, 108)
                                   .addGroup(contentPaneLayout.createParallelGroup()
                                           .addComponent(label1)
                                           .addComponent(label2))
                                   .addGap(41, 41, 41)
                                   .addGroup(contentPaneLayout.createParallelGroup()
                                           .addComponent(subGYSbtn, GroupLayout.PREFERRED_SIZE, 116, GroupLayout.PREFERRED_SIZE)
                                           .addComponent(textField1, GroupLayout.PREFERRED_SIZE, 245, GroupLayout.PREFERRED_SIZE)
                                           .addComponent(textField2, GroupLayout.PREFERRED_SIZE, 245, GroupLayout.PREFERRED_SIZE))
                                   .addContainerGap(199, Short.MAX_VALUE))
           );
           contentPaneLayout.setVerticalGroup(
                   contentPaneLayout.createParallelGroup()
                           .addGroup(contentPaneLayout.createSequentialGroup()
                                   .addGap(78, 78, 78)
                                   .addGroup(contentPaneLayout.createParallelGroup()
                                           .addComponent(label1)
                                           .addGroup(contentPaneLayout.createSequentialGroup()
                                                   .addComponent(textField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                                   .addGap(18, 18, 18)
                                                   .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                                           .addComponent(textField2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                                           .addComponent(label2))))
                                   .addGap(44, 44, 44)
                                   .addComponent(subGYSbtn)
                                   .addContainerGap(197, Short.MAX_VALUE))
           );
           pack();
           setLocationRelativeTo(getOwner());
           // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
       }

       // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
       private JLabel label1;
       private JTextField textField1;
       private JLabel label2;
       private JTextField textField2;
       private JButton subGYSbtn;
       // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
   }
